<?php

$plugin_info = array(
'pi_name'			=> 'mp3 Player',
'pi_version'		=> '0.1',
'pi_author'			=> 'Sean Gravener',
'pi_author_url'		=> 'http://sean.gravener.net/',
'pi_description'	=> 'WP Audio Player for EE',
'pi_usage'			=> media::usage()
);

class media {
	
	function mp3()
	{
		global $TMPL;
		$file_url = $TMPL->fetch_param('file');
		
		// random string
		$chars = "abcdefghijkmnopqrstuvwxyz023456789";
	    srand((double)microtime()*1000000);
	    $i = 0;
	    $randString = "";

	    while ($i <= 7) {
	        $num = rand() % 33;
	        $tmp = substr($chars, $num, 1);
	        $randString = $randString . $tmp;
	        $i++;
	    }
			
		$html = '<p id="media-' . $randString . '">Alternative content</p>';
		$html .= '<script type="text/javascript">';
		$html .= 'AudioPlayer.embed("media-' . $randString . '", {soundFile: "' . $file_url . '"});';
		$html .= '</script>';

		return $html;
	}
	
	function pdf()
	{
		global $TMPL;
		$scribd_url = $TMPL->fetch_param('scribd_url');
		
		$scribdHTML = '<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="doc_42704270269018" name="doc_42704270269018" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" align="middle"	height="500" width="450">';
		$scribdHTML .= '<param name="movie"	value="' . $scribd_url . '">';
		$scribdHTML .= '<param name="quality" value="high">';
		$scribdHTML .= '<param name="play" value="true">';
		$scribdHTML .= '<param name="loop" value="true">';
		$scribdHTML .= '<param name="scale" value="showall">';
		$scribdHTML .= '<param name="wmode" value="opaque">';
		$scribdHTML .= '<param name="devicefont" value="false">';
		$scribdHTML .= '<param name="bgcolor" value="#ffffff">';
		$scribdHTML .= '<param name="menu" value="false">';
		$scribdHTML .= '<param name="allowFullScreen" value="true">';
		$scribdHTML .= '<param name="allowScriptAccess" value="always">';
		$scribdHTML .= '<param name="salign" value="">';
		$scribdHTML .= '<param name="mode" value="slide">';
		$scribdHTML .= '<embed src="' . $scribd_url . '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" play="true" loop="true" scale="showall" wmode="opaque" devicefont="false" bgcolor="#ffffff" name="doc_42704270269018_object" menu="true" allowfullscreen="true" allowscriptaccess="always" salign="" type="application/x-shockwave-flash" align="middle" mode="list" height="500" width="450"></embed>';
		$scribdHTML .= '</object>';
	
		return $scribdHTML;
	}
	
	// ----------------------------------------
	//  Plugin Usage
	// ----------------------------------------
	
	// This function describes how the plugin is used. Make sure and use output buffering
		
function usage(){
ob_start(); 
?>

EXAMPLES:

{exp:media:mp3 file="{site_url}mp3/name.mp3"}
{exp:media:pdf scribed_url=" ... "}

NOTES:

Javascript and flash files must be setup in the <head></head> manually for now.


<?php
$buffer = ob_get_contents();
	
ob_end_clean(); 

return $buffer;

}	
}
?>